import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
public class DeleteFile extends Form implements CommandListener{
	private FileManagerMIDlet filemanager;
	private ListContend list;
	private Command ok, cancel;
	private String url, filename;
	private FileConnection fileconn;
	private Connector conn;
	public DeleteFile(FileManagerMIDlet fm, ListContend list, String upurl, String filename){
		super("Xac nhan xoa file");
		this.filemanager = fm;
		this.filename = filename;
		this.url = upurl;	
		this.list = list;	
		ok = new Command("Dong y", Command.OK, 0);
		cancel = new Command("Huy", Command.CANCEL, 1);
		if(filename.endsWith("/") == true){
			String foldername = filename.substring(0, filename.length() -1);
			append("Ban that su muon xoa thu muc: " + foldername.toUpperCase() + " va tat ca nhung gi ben trong no !");
		}
		else
			append("Ban that su muon xoa tap tin: " + filename.toUpperCase());
		addCommand(ok);
		addCommand(cancel);
		setCommandListener(this);
	}
	public void delete(){
		try{
			fileconn = (FileConnection)conn.open(url + filename);
			fileconn.delete();
			list.getContend(url, null);
			if(filename.endsWith("/") == true)
				filemanager.showAlert("Da xoa thu muc !", list);		
			else
				filemanager.showAlert("Da xoa tap tin !", list);	
		}
		catch(Exception e){}
	}
	public void commandAction(Command c, Displayable d){
		if(c == ok){			
			delete();
		}
		if(c == cancel){
			filemanager.showContend(url, null);
		}
	}
}